var $,layer;
var userId = JSON.parse(localStorage.getItem("user")).userId;
layui.use(['jquery', 'layer'], function () {
    $ = layui.jquery,
    layer = layui.layer;
    $('#productName').text($('#proName', window.parent.document).val())
    $('#id').text($('#proId', window.parent.document).val())
    $('#productId').val($('#productId', window.parent.document).val())
})
//确定
$("#sub").on("click",function () {
    var id = $("#id").text();
    var result = $("input:checked").val();
    var remarks = $("textarea[name=remarks]").val();
    var productId = $("#productId").val();
    var data= {
        'id': id,
        'result': result,
        'remarks': remarks,
        'implementId': userId,
        'productId': productId
    }
    console.log(data);
    $.ajax({
        url: '/toExamine/updateProductCourseRecord',
        type: 'post',
        dataType: 'json',
        data: data,
        success:function (item) {
            if (item.data){
                layer.msg('审核成功');
                if (result == 1){
                    result = 2
                } else if (result == 3){
                    result = 1
                }
                addAuditLog(result, remarks,id);
                parent.getProductList('','','','');
                parent.getProductNums();
            } else{
                layer.msg('审核失败');
            }
        }
    })
    //关闭窗口
    var layer = parent.layer;
    layer.close(layer.index);
});
//添加商品审核日志
function addAuditLog(result, remarks,id){
    $.ajax({
        url: '/toExamine/addAuditLog',
        type: 'post',
        dataType: 'json',
        data: {
            'tableName': 'js_course_record',
            'type': result,
            'userId': userId,
            'remark': remarks,
            "aduitId": id,
            "aduitLogType": 1,//商品
        },
    })
}
//取消
$("#cancel").on("click",function () {
    var layer = parent.layer;
    layer.close(layer.index);
});